import { Component, OnInit } from '@angular/core';
import { NavController } from '@ionic/angular';
import { HttpService } from 'src/app/service/http.service';
import { PopwinService } from 'src/app/service/popwin.service';
import { UrlService } from 'src/app/service/url.service';
import { ToolService } from 'src/app/service/tool.service';
import { ConfigService } from 'src/app/service/config.service';

@Component({
  selector: 'app-conpro',
  templateUrl: './conpro.page.html',
  styleUrls: ['./conpro.page.scss'],
})
export class ConproPage implements OnInit {
  public questionData={"privacy":"","rule":"","saving":"","withdraw":"","browser":""};
  public stateData={"isPrivacy":false,"isRule":false,"isSaving":true,"isWithdraw":false,"isBrowser":false};
  constructor(private navCtrl: NavController,private http:HttpService,private popWin:PopwinService) { }

  ngOnInit() {
    this.questionsNet();
  }

  backClick() {
    this.navCtrl.navigateBack("tabs/my");
  }

  changeTab(typeStr:String){
    switch(typeStr){
      case 'privacy':{
        this.stateData={"isPrivacy":true,"isRule":false,"isSaving":false,"isWithdraw":false,"isBrowser":false};
         break;
      }
      case 'rule':{
        this.stateData={"isPrivacy":false,"isRule":true,"isSaving":false,"isWithdraw":false,"isBrowser":false};
        break;
      }
      case 'saving':{
        this.stateData={"isPrivacy":false,"isRule":false,"isSaving":true,"isWithdraw":false,"isBrowser":false};
        break;
      }
      case 'withdraw':{
        this.stateData={"isPrivacy":false,"isRule":false,"isSaving":false,"isWithdraw":true,"isBrowser":false};
        break;
      }
      case 'browser':{
        this.stateData={"isPrivacy":false,"isRule":false,"isSaving":false,"isWithdraw":false,"isBrowser":true};
        break;
      }
  }
  }
  
  questionsNet() {
    let that = this;
    let obj = "{\"type\":\"" + "questions" + "\"}";
    this.http.get(UrlService.OTHER_CONFIG, { "callback": "JSONP_CALLBACK" , "data": ToolService.aesEncode(obj)}).subscribe(res => {
      let data = res.json();
      ToolService.setEncrypt(data.encrypt);
      if (data.code == ConfigService.SUCCESS_CODE) {
        let temp = data.data;
        let res = ToolService.aesDecodeToJson(temp);
        that.questionData=res;
        console.log(res);
      } else if (data.code == ConfigService.FAIL_CODE) {
        that.popWin.toast(data.message);
      } else if (data.code == ConfigService.LOGIN_CODE) {
        that.navCtrl.navigateForward("/login");
      }
    }, error => {
      console.log("error", error);
    });
  }
}
